package com.cjb.cloudsystem.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjb.cloudsystem.entity.SysLogLogin;
import com.cjb.cloudsystem.service.SysLogLoginService;
import com.cjb.cloudsystem.vo.SysLogLoginVO;
import com.cjb.common.util.JsonUtils;
import com.cjb.common.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 1.0.0 2023-08-30
 * @Package IntelliJ IDEA
 * @Class SysLogLoginControl
 * @Date 2023-08-30
 */
@RestController
@Tag(name = "sysLogLogin")
@RequestMapping(value = {"sys/log/login"})
@ApiResponses(@ApiResponse(responseCode = "200", description = "接口请求成功"))
@AllArgsConstructor
@Slf4j
public class SysLogLoginController {
    /*
     * 注入事物类
     */
    private final SysLogLoginService sysLogLoginService;

    /**
     * 单个保存
     *
     * @Author 1.0.0 2023-08-30
     * @Value
     * @Title
     */
    @PostMapping("/save")
    @Operation(summary = "单个保存")

    public Result<Boolean> save(@RequestBody SysLogLogin sysLogLogin) {
        return Result.success(sysLogLoginService.save(sysLogLogin));
    }

    /**
     * 批量保存
     *
     * @Author 1.0.0 2023-08-30
     * @Value
     * @Title
     */
    @PostMapping("/listSave")
    @Operation(summary = "批量保存")
    public Result<Integer> listSave(@RequestBody List<SysLogLogin> sysLogLogin) {
        return Result.success(sysLogLoginService.listSave(sysLogLogin));
    }

    /**
     * 单个查询
     *
     * @Author 1.0.0 2023-08-30
     * @Value
     * @Title
     */
    @GetMapping("/queryById")
    @Operation(summary = "单个查询-通过ID")
    public Result<SysLogLogin> queryById(@RequestBody SysLogLogin sysLogLogin) {
        return Result.success(sysLogLoginService.queryById(sysLogLogin));
    }

    /**
     * 分页查询
     *
     * @Author 1.0.0 2023-08-30
     * @Value
     * @Title
     */
    @GetMapping("/page")
    @Operation(summary = "分页查询-通过页码")
    public Result<Page<SysLogLogin>> queryPage(@ParameterObject @Valid SysLogLoginVO sysLogLogin) {
        log.info("进入登录页 {}", JsonUtils.toJsonString(sysLogLogin));
        Page sysLogLoginPage = new Page<SysLogLogin>(sysLogLogin.getPage(),sysLogLogin.getLimit());
        return Result.success(sysLogLoginService.queryPage(sysLogLoginPage, sysLogLogin));
    }

    /**
     * 批量更新
     *
     * @Author 1.0.0 2023-08-30
     * @Value
     * @Title
     */
    @PostMapping("/listUpdate")
    @Operation(summary = "批量更新")
    public Result<String> listUpdate(@RequestBody List<SysLogLogin> sysLogLogin) {
        sysLogLoginService.listUpdate(sysLogLogin);
        return Result.success();
    }


    /**
     * 批量删除
     *
     * @Author 1.0.0 2023-08-30
     * @Value
     * @Title
     */
    @PostMapping("/listDelete")
    @Operation(summary = "批量删除")
    public Result<String> listDelete(@RequestBody List<SysLogLogin> sysLogLogin) {
        sysLogLoginService.listDelete(sysLogLogin);
        return Result.success();
    }

    /**
     * 通过id删除
     *
     * @Author 1.0.0 2023-08-30
     * @Value
     * @Title
     */
    @PostMapping("/deleteById")
    @Operation(summary = "单个删除-通过ID")
    public Result<String> deleteById(@RequestBody SysLogLogin sysLogLogin) {
        sysLogLoginService.deleteById(sysLogLogin);
        return Result.success();
    }

    /**
     * 返回全部信息
     *
     * @Author 1.0.0 2023-08-30
     * @Value
     * @Title
     */
    @PostMapping("/returnAllData")
    @Operation(summary = "返回所有信息")
    public Result<List<SysLogLogin>> returnAllData() {
        return Result.success(sysLogLoginService.returnAllData());
    }

}
